package com.ellricky.baselib.adapter;

import android.app.Activity;
import android.widget.TextView;

import com.andr.common.ui.adapter.BaseRecyclerAdapter;
import com.andr.common.ui.adapter.SmartViewHolder;
import com.andr.common.util.ResUtil;
import com.ellricky.baselib.R;
import com.ellricky.baselib.entity.IdNameEntity;
import com.ellricky.baselib.entity.RankEntity;
import com.ellricky.baselib.util.GlideUtil;
import com.flyco.roundview.RoundTextView;
import com.flyco.roundview.RoundViewDelegate;

import de.hdodenhof.circleimageview.CircleImageView;

public class ErCodeActAdapter extends BaseRecyclerAdapter<IdNameEntity> {

    private Activity ctx;
    private int mCurPos = -1;

    public ErCodeActAdapter(Activity activity) {
        super(R.layout.base_adapter_ercode_act);
        ctx = activity;
    }

    @Override
    public void onBindViewHolder(SmartViewHolder holder, IdNameEntity model, int position) {
        RoundTextView tvName = holder.itemView.findViewById(R.id.tvActName);
        tvName.setText(model.getName());

        if (mCurPos == position) {
            enableRoundTv(tvName, true);
        } else {
            enableRoundTv(tvName, false);
        }

    }

    public void onClickItem(int position){
        mCurPos = position;
        notifyDataSetChanged();
    }


    private void enableRoundTv(RoundTextView rtv, boolean enable) {
        RoundViewDelegate delegate = rtv.getDelegate();
        int black = ResUtil.getColor(ctx, R.color.common_main_black);
        int white = ResUtil.getColor(ctx, R.color.common_main_white);
        int gray = ResUtil.getColor(ctx, R.color.common_gray_66);
        int gray_cc = ResUtil.getColor(ctx, R.color.base_color_cc);

        if (enable) {
            delegate.setBackgroundColor(black);
        } else {
            delegate.setBackgroundColor(gray_cc);
        }
        rtv.setTextColor(white);
        rtv.setSelected(enable);
    }
}
